package cn.yueranzs.login.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.yueranzs.response.UserResultCode;
import cn.yueranzs.system.service.LoginService;
import cn.yueranzs.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yueranzs
 * @date 2021/11/22 13:59
 */
@Api(tags = "用户登录控制器")
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private LoginService loginService;

    @ApiOperation(value = "验证码",notes = "获取验证码")
    @GetMapping("/getRandomCode")
    public Result getRandomCode(@RequestParam String randomCode){
        if (ObjectUtil.isEmpty(randomCode)) {
            return Result.error(500,"请输入验证码！");
        }
        return Result.successData(loginService.getRandomCode(randomCode));
    }

    @ApiOperation(value = "用户头像",notes = "获取用户头像")
    @GetMapping("/getUserAvatar")
    public Result getUserAvatar(@RequestParam String username){
        if (ObjectUtil.isEmpty(username)) {
            return Result.error(500,"请输入账号！");
        }
        return Result.successData(loginService.getUserAvatar(username));
    }

    @ApiOperation(value = "登陆人信息",notes = "获取登陆人信息")
    @GetMapping("/getUser")
    public Result getUser(){
        return Result.successData(loginService.getUser());
    }

    @ApiOperation(value = "登陆人菜单权限",notes = "获取登陆人菜单权限")
    @GetMapping("/getUserMenuList")
    public Result getUserMenuList(){
        return Result.successData(loginService.getUserMenus());
    }


    @ApiOperation(value = "退出登录",notes = "退出登录")
    @GetMapping("/logout")
    public JSONObject logout(){
        return loginService.logout();
    }



}
